<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <div v-mytext="msg"></div>
        <div v-myhtml="str"></div>
    </div>
    <script src="./node_modules/vue/dist/vue.js"></script>
    <script>
        //v-text可以将数据绑定给元素的innerText 在数据发生变化的时候，innerText也会随之变化

        //自己定义一个mytext来实现text的功能
        Vue.directive("mytext", {
            bind(el, binding){
                //将用户所赋值的表达式msg的值赋值给div的innerText
                el.innerText = binding.value;
            },
            update(el, binding){
                el.innerText = binding.value;                
            }
        })

        Vue.directive("myhtml", {
            bind(el, binding){
                //将用户所赋值的表达式msg的值赋值给div的innerText
                el.innerHTML = binding.value;
            },
            update(el, binding){
                el.innerHTML = binding.value;                
            }
        })

        var vm = new Vue({
            el: "#app",
            data: {
                msg: "让我将你心儿摘下",
                str: "<h1>试着将它慢慢融化</h1>"
            }
        })
    </script>
</body>

</html>